﻿'''
1002 查找共用字符
给你一个字符串数组 words ，请你找出所有在 words 的每个字符串中都出现的共用字符（包括重复字符），并以数组形式返回。
你可以按 任意顺序 返回答案。
示例 1：
输入：words = [bella,label,roller]
输出：[e,l,l]
示例 2：
输入：words = [cool,lock,cook]
输出：[c,o]
提示：
1 <= words.length <= 100
1 <= words[i].length <= 100
words[i] 由小写英文字母组成
'''
#读取输入
words = input().split(',')

hash_first = [0] * 26
#首字符串初始化数组
for c in words[0]:
    hash_first[ord(c) - ord('a')] += 1
#依次遍历其他字符串，并更新数组
for i in range(1,len(words)):
    hash_other = [0] * 26
    for c in words[i]:
        hash_other[ord(c) - ord('a')] += 1
    #比较各个字母，取出现次数小的
    for j in range(26):
        if hash_first[j] > hash_other[j]:
            hash_first[j] = hash_other[j]
#输出次数大于0的公共字符
result = []
for i in range(26):
    if hash_first[i] > 0:
        current_chars = [chr(ord('a') + i)] * hash_first[i]
        result.extend(current_chars)
print(','.join(result))


'''
class Solution:
    def commonChars(self,words:list[str])->list[str]:
        if not words:
            return []
        hash_first = [0] * 26
        result = []
        for i,c in enumerate(words[0]):
            #用首字符串初始化第一个表
            hash_first[ord(c)-ord('a')] += 1
        for i in range(1,len(words)):
            hash_other = [0] * 26
            for j,c in enumerate(words[i]):
                hash_other[ord(c) - ord('a')] += 1
            for k in range(26):
                #如果后续单词中字符个数小于首字符串则取后者
                if hash_first[k] > hash_other[k]:
                    hash_first[k] = hash_other[k]
        for i in range(26):
            while hash_first[i] != 0:
                result.append(chr(ord('a') + i))
                hash_first[i] -= 1
        return result
#示例
if __name__ == '__main__':
    words = ["bella","label","roller"]
    words1 = ["cool","lock","cook"]
    words2 = []
    words3 = ["cool","test","hash"]
    print(Solution().commonChars(words))
    print(Solution().commonChars(words1))
    print(Solution().commonChars(words2))
    print(Solution().commonChars(words3))
'''



